import 'dart:async';

import 'package:flutter/services.dart';

import '../../constant/channel_name_constant.dart';
import '../../utils/log_util.dart';

///EventChannel是一种native向flutter发送数据的单向通信方式，
///flutter无法返回任何数据给native。
///主要用于native向flutter发送手机电量变化、网络连接变化、陀螺仪、传感器等

class BaseEventChannel extends EventChannel{

  static final BaseEventChannel _instance = BaseEventChannel._internal(ChannelNameConstant.eventChannelName);

  factory BaseEventChannel() => _instance;

  BaseEventChannel._internal(super.name);

  void initEventChannel(){
    StreamSubscription streamSubscription = _instance.receiveBroadcastStream().listen((event) {
      LogUtil.stdPrint(event);
    },onDone:(){

    },onError: (dynamic error){

    },cancelOnError: true);
  }
}
